﻿<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>代码参考</title>
    <link href="../../Scripts/jquery-easyui/themes/bootstrap/easyui.css" rel="stylesheet" />
    <script src="../../Scripts/jquery-easyui/jquery.min.js"></script>
    <script src="../../Scripts/jquery-easyui/jquery.easyui.min.js"></script>
    <script src="../../Scripts/jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
    <link href="../../Content/themes/icon.css" rel="stylesheet" />
    <link href="../../Content/themes/table.css" rel="stylesheet" />
    <link href="../../Content/formstyles.css" rel="stylesheet" />
    <script src="../../Content/js/common.js"></script>  
</head>
<body>   
    <div id="ui_main_layout" class="easyui-layout" data-options="fit:true,border:false">
        <div data-options="region:'center',border:false">
            <div><table id="dg0"></table> </div>          
</div>

        <div class="easyui-panel" title="基本信息" style="width:100%;height:auto;padding:10px;">
            <div>
                <input type="text" class="easyui-textbox" id="claimBy" data-options="width:200,label:'报销人：',labelPosition:'before',labelWidth:80,labelAlign:'right', required:true,disabled:false" />
                <input class="easyui-combobox" id="claimDept" name="claimDept" data-options="
                           editable:false,
                           width:200,
                           label:'所在部门：',
                           labelPosition:'before',labelWidth:80,labelAlign:'right',
                           required:true, valueField: 'DepartmentName', textField: 'DepartmentName',url: '/Common/SelectDepartment' ">
                <input type="text" id="claimTime" class="easyui-datebox" data-options="width:200,label:'报销时间：',labelPosition:'before',labelWidth:80,labelAlign:'right',disabled:false" />
                <input class="easyui-combobox" id="periodEdit" name="period" data-options="editable:false,
                                width:200,
                           label:'财务期间：',labelWidth:80,
                           labelPosition:'before',labelAlign:'right',
                               valueField: 'InfoName', textField: 'InfoName',url: '/Common/SelectBasicInfo?p=815' ">

                <input class="easyui-combobox" id="s-group" data-options="editable:false,width:200,
                                 label:'分组方法：',labelPosition:'before',labelAlign:'right',
                                   valueField: 'value', textField: 'label',value:'dept',data: [
                                   {    label: '按部门',
			                            value: 'dept'
		                            },{
			                            label: '按项目',
			                            value: 'projectNo'
		                            },]" />
                <input class="easyui-combobox" id="s-status" data-options="editable:false,width:200,
                                 label:'单据状态：',labelPosition:'before',labelAlign:'right',
                                   valueField: 'value', textField: 'label',value:'all',data: [
                                   {    label: '全部',
			                            value: 'all'
		                            },{
			                            label: '待审核',
			                            value: '0'
		                            },{
			                            label: '已审核',
			                            value: '1'
		                            },]" />
            </div> <div>
                <input id="claimRemark" class="easyui-textbox" data-options="width:400,height:40,label:'摘要：',labelWidth:80,labelPosition:'before',labelAlign:'right',multiline:true,prompt:'某某人报销某费用',">
                <input type="text" class="easyui-textbox" id="total" data-options="width:200,label:'总金额：',labelPosition:'before',labelWidth:80,labelAlign:'right',editable:false" />

            </div>


            <div id="dlg" class="easyui-dialog" style="width:400px" data-options="closed:true,modal:true,border:'thin',buttons:[{
				text:'保存',
				iconCls:'icon-ok',
				handler:function(){saveEntry()}
			},{
				text:'取消',
				iconCls:'icon-cancel',
				handler:function(){$('#dlg').dialog('close')}
			}]">
                <form id="fm" method="post" novalidate style="margin:0;padding:20px 50px">
                    <div style="margin-bottom:2px">
                        <input name="ItemCode" id="ItemCode" class="easyui-combox" data-options="label:'对象ID:', required:false," style="width:100%">
                    </div>
                    <div style="margin-bottom:10px">
                        <input name="ItemName" id="ItemName" class="easyui-textbox" data-options="label:'对象名称:', required:true," style="width:100%">
                    </div>
                    <div style="margin-bottom:10px">
                        <input name="d_remark" id="d_remark" class="easyui-textbox" label="备注:" style="width:100%">
                    </div>
                </form>
            </div>
            <!--InfoID,InfoName,ParentID,Remark,OrderID-->
            <script type="text/javascript">
                var columns = [[
                             { field: "InfoID", width: "120", title: "对象ID", align: 'center', hidden: false },
                             { field: "InfoName", width: "120", title: "对象名称", align: 'center' },
                             { field: "ParentID", width: "180", title: "父ID", align: 'center', },
                             { field: "OrderID", width: "120", title: "排序码", align: 'center' },
                             { field: "Remark", width: "120", title: "对象说明", align: 'center', formatter: showLongString, },
                ]];

                var cPid = 0;
                var cInfoID;
                //利用cInfoID加载子对象
                //利用cPid加载上级对象
                function loadSubInfo(dgID, infoID) {
                    $("#" + dgID).datagrid({       //初始化datagrid
                        url: "/Dev/getBasicInfo?&r=" + Math.random(),
                        striped: true, rownumbers: true, pagination: true, pageSize: 20, singleSelect: true,
                        queryParams: {
                            "InfoID": infoID,
                            "type": 'subItems',
                        },
                        idField: 'InfoID',
                        sort: 'OrderID',
                        order: 'desc',
                        pageList: [20, 40, 60, 80, 100],
                        columns: columns,
                        toolbar: [{
                            iconCls: 'icon-up',
                            text: '上一级',
                            handler: function () {
                                var row = $('#dg0').datagrid('getRows');
                                if (row.length == 0) {
                                    //根据记忆加载上一级
                                    $('#dg0').datagrid('load', {
                                        "InfoID": cInfoID,
                                        "type": 'parents',
                                    });
                                    $('#dg0').datagrid('clearSelections');
                                } else {
                                    //根据当前第一行记录加载上一级
                                    if (row[0].ParentID == 0) {
                                        $.show_warning("提示", "没有上一级了！");
                                    } else {
                                        $('#dg0').datagrid('load', {
                                            "InfoID": row[0].ParentID,
                                            "type": 'parents',
                                        });
                                        $('#dg0').datagrid('clearSelections');
                                    }
                                }
                            }
                        }, '-', {
                            iconCls: 'icon-down',
                            text: '下一级',
                            handler: function () {
                                var row = $('#dg0').datagrid('getSelected');
                                if (row) {
                                    //cPid = row.ParentID;
                                    cInfoID = row.InfoID;
                                    $('#dg0').datagrid('load', {
                                        "InfoID": cInfoID,
                                        "type": 'subItems',
                                    })
                                    $('#dg0').datagrid('clearSelections');
                                }
                            }

                        }, '-',
                            {
                                iconCls: 'icon-add',
                                handler: function () {
                                    this.select

                                }
                            }, '-', {
                                iconCls: 'icon-edit',
                                handler: function () { alert('edit') }
                            }, '-', {
                                iconCls: 'icon-delete',
                                handler: function () { alert('del') }
                            }],
                        onSelect: function (rowIndex, rowData) {
                        },
                        onDblClickRow: function (rowIndex, rowData) {

                        },
                        onLoadSuccess: function (data) { }
                    });

                }


                $(function () {
                    //var dgobj = $("#dg0");
                    //loadSubInfo(dgobj, 0);
                    loadSubInfo('dg0', 0);
                    //$("#dg0").datagrid({       //初始化datagrid
                    //    url: "/Dev/getSubInfo?&r=" + Math.random(),
                    //    striped: true, rownumbers: true, pagination: true, pageSize: 20, singleSelect: true,
                    //    queryParams: {
                    //        "InfoID": 0,
                    //    },
                    //    idField: 'InfoID',
                    //    sort: 'OrderID',
                    //    order: 'desc',
                    //    pageList: [20, 40, 60, 80, 100],
                    //    //frozenColumns: [[]],
                    //    columns: columns,
                    //    //toolbar: toolbar.length == 0 ? null : toolbar,
                    //    onSelect: function (rowIndex, rowData) {
                    //        //LoadSubInfo();
                    //    },
                    //    onDblClickRow: function (rowIndex, rowData) {
                    //     //   loadSubInfo('dg1', rowData.InfoID);
                    //    },
                    //    onLoadSuccess: function (data) { }
                    //});
                });



                function ui_main_exportdata() {
                    $.show_alert("消息", "功能待发布！");
                }

                var lock = false;
                //下发图纸
                function saveEntry() {

                    if (!$("#fm").form('validate')) {//表单校验
                        $.show_alert("错误", "表单校验未通过！请注意录入数据格式");
                        return;
                    } else {
                        if (lock) { return; } else { lock = true; }
                    }
                    $.ajax({
                        url: "/Draw/issueDraw",
                        type: "post",
                        data: {
                            "mainItemCode": $('#mainItemCode').combobox("getText"),
                            "mainItemName": $('#mainItemCode').combobox("getValue"),
                            "subItemCode": $('#subItemCode').combobox("getText"),
                            "subItemName": $('#subItemCode').combobox("getValue"),
                            "drawId": uuid(20, 10),
                            "remark": $('#d_remark').textbox('getValue'),
                        },
                        dataType: 'json',//html\script\text\xml\json
                        beforeSend: function () { },//
                        complete: function () { lock = false; },
                        timeout: 1000,
                        success: function (data) {
                            if (data.success) {
                                $.show_alert("成功", "下发成功！");
                                $('#fm').form('clear');
                                $('#dlg').dialog('close');
                                $("#ui_main_dg").datagrid("reload");//.datagrid('clearSelections').datagrid('clearChecked');
                            } else {
                                $.show_alert("提示", data.msg);
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            if (textStatus == "timeout") {
                                $.show_alert("提示", "请求超时，请刷新当前页重试！");
                            }
                            else {
                                $.show_alert("错误", textStatus + "：" + errorThrown);
                            }
                        },

                    });
                }


                //删除，取消下发图纸
                function DeldrawMgr() {
                    var row = $("#ui_main_dg").datagrid("getSelected");
                    if (row == null || row.length < 1) {
                        $.show_alert("提示", "请先勾选要删除的图纸");
                        return;
                    }
                    if (row.drawId == null || row.drawId == '') {
                        $("#ui_main_dg").datagrid('clearSelections').datagrid('clearChecked');
                        return;
                    }
                    if (row.confirmBy.length > 2) {
                        $.show_alert("提示", "该图纸已确认，无法删除");
                        return;
                    }
                    $.ajax({
                        url: "/Draw/delDraw",
                        type: "post",
                        data: {
                            "drawId": row.drawId,
                        },
                        dataType: 'json',//html\script\text\xml\json
                        // beforeSend: function () { },//
                        // complete: function () { lock = false; },
                        timeout: 1000,
                        success: function (data) {
                            if (data.success) {
                                $.show_alert("成功", "删除成功！");
                                $("#ui_main_dg").datagrid("reload");//.datagrid('clearSelections').datagrid('clearChecked');
                            } else {
                                $.show_alert("提示", data.msg);
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            if (textStatus == "timeout") {
                                $.show_alert("提示", "请求超时，请刷新当前页重试！");
                            }
                            else {
                                $.show_alert("错误", textStatus + "：" + errorThrown);
                            }
                        },
                    });


                }
                //确认图纸
                function confirmdrawMgr() {
                    var row = $("#ui_main_dg").datagrid("getSelected");
                    if (row == null || row.length < 1) {
                        $.show_alert("提示", "请先勾选要确认的图纸");
                        return;
                    }
                    if (row.drawId == null || row.drawId == '') {
                        $("#ui_main_dg").datagrid('clearSelections').datagrid('clearChecked');
                        return;
                    }
                    if (row.confirmBy.length > 2) {
                        $.show_alert("提示", "该图纸已确认");
                        return;
                    }
                    $.ajax({
                        url: "/Draw/confirmDraw",
                        type: "post",
                        data: {
                            "drawId": row.drawId,
                        },
                        dataType: 'json',//html\script\text\xml\json
                        // beforeSend: function () { },//
                        // complete: function () { lock = false; },
                        timeout: 1000,
                        success: function (data) {
                            if (data.success) {
                                $.show_alert("成功", "确认成功！");
                                //$('#fm').form('clear');
                                //$('#dlg').dialog('close');
                                $("#ui_main_dg").datagrid("reload");//.datagrid('clearSelections').datagrid('clearChecked');
                            } else {
                                $.show_alert("提示", data.msg);
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            if (textStatus == "timeout") {
                                $.show_alert("提示", "请求超时，请刷新当前页重试！");
                            }
                            else {
                                $.show_alert("错误", textStatus + "：" + errorThrown);
                            }
                        },
                    });
                }

                //取消确认图纸
                function unconfirmdrawMgr() {
                    var row = $("#ui_main_dg").datagrid("getSelected");
                    if (row == null || row.length < 1) {
                        $.show_alert("提示", "请先勾选要取消确认的图纸");
                        return;
                    }
                    if (row.drawId == null || row.drawId == '') {
                        $("#ui_main_dg").datagrid('clearSelections').datagrid('clearChecked');
                        return;
                    }
                    if (row.confirmBy == null || row.confirmBy == "") {
                        $.show_alert("提示", "该图纸未确认");
                        return;
                    }
                    $.ajax({
                        url: "/Draw/confirmDraw",
                        type: "post",
                        data: {
                            "drawId": row.drawId,
                            "type": 'unConfirm'
                        },
                        dataType: 'json',//html\script\text\xml\json
                        // beforeSend: function () { },//
                        // complete: function () { lock = false; },
                        timeout: 1000,
                        success: function (data) {
                            if (data.success) {
                                $.show_alert("成功", "取消确认成功！");
                                $("#ui_main_dg").datagrid("reload");//.datagrid('clearSelections').datagrid('clearChecked');
                            } else {
                                $.show_alert("提示", data.msg);
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            if (textStatus == "timeout") {
                                $.show_alert("提示", "请求超时，请刷新当前页重试！");
                            }
                            else {
                                $.show_alert("错误", textStatus + "：" + errorThrown);
                            }
                        },

                    });

                }


                //下发图纸
                function assigndrawMgr() {
                    $('#dlg').dialog('open').dialog('center').dialog('setTitle', '下发图纸');
                    // url = "../../Financial/ExpenseClaimEntyHandle?claimId=" + claimId + "&method=insert" + "&rowId=" + rowId;
                    $('#mainItemCode').combobox({
                        mode: 'remote',  //模式： 远程获取数据
                        url: '/Common/AutoComplete_ItemCode',  //远程数据请求地址
                        valueField: 'FName', 　　//value对应的属性字段
                        textField: 'FNumber',　　　 //text对应的属性字段
                        formatter: function (row) {
                            var opts = $(this).combobox('options');
                            return row[opts.textField] + " " + row[opts.valueField];
                        },
                        onChange: function (newValue, oldValue) {
                            $("#mainItemName").textbox('setValue', newValue);

                            $('#subItemCode').combobox({
                                url: '/Bom/getBomChildItem?q=' + $('#mainItemCode').combobox("getText"),
                                valueField: 'FName',
                                textField: 'FNumber',
                                formatter: function (row) {
                                    var opts = $(this).combobox('options');
                                    return row[opts.textField] + " " + row[opts.valueField];
                                },
                                onChange: function (newValue, oldValue) {
                                    $("#subItemName").textbox('setValue', newValue);
                                }
                            });
                        }

                    });
                    $('#fm').form('clear');
                }



            </script>
        </div>    
</body>
    </html>
